# Maintainer: Haroogan <Haroogan@gmail.com>

_realname='tor'
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.7.6
pkgrel=1
pkgdesc="Anonymizing overlay network (mingw-w64)"
url="https://www.torproject.org/"
license=('BSD')
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-libevent"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-ca-certificates")
options=('strip')
source=("https://dist.torproject.org/${_realname}-${pkgver}.tar.gz"{,.asc})
sha256sums=('493a8679f904503048114aca6467faef56861206bab8283d858f37141d95105d'
            'SKIP')
validpgpkeys=('B35BF85BF19489D04E28C33C21194EBB165733EA') # Nick Mathewson

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"

  mkdir -p "${srcdir}/build-${MINGW_CHOST}"

  cd "build-${MINGW_CHOST}"

  CPPFLAGS="-isystem ${MINGW_PREFIX}/include"
  CFLAGS="-pipe -O3 -fomit-frame-pointer -funroll-loops"
  LDFLAGS="-s -Wl,-s"
  "${srcdir}/${_realname}-${pkgver}/configure" \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --disable-bufferevents \
    --disable-seccomp \
    --disable-libscrypt

  make
}

package() {
  cd "build-${MINGW_CHOST}"

  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/${_realname}-${pkgver}"

  install -D "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -d           "${pkgdir}${MINGW_PREFIX}/var/lib/tor"
}
